package io.renren.modules.wx.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.wx.entity.NoteEntity;
import io.renren.modules.wx.service.NoteService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author linmingze
 * @email ${email}
 * @date 2022-10-18 10:41:32
 */
@RestController
@RequestMapping("wx/note")
public class NoteController {
    @Autowired
    private NoteService noteService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("wx:note:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = noteService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{noteId}")
    @RequiresPermissions("wx:note:info")
    public R info(@PathVariable("noteId") Integer noteId){
		NoteEntity note = noteService.getById(noteId);

        return R.ok().put("note", note);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("wx:note:save")
    public R save(@RequestBody NoteEntity note){
		noteService.save(note);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("wx:note:update")
    public R update(@RequestBody NoteEntity note){
		noteService.updateById(note);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("wx:note:delete")
    public R delete(@RequestBody Integer[] noteIds){
		noteService.removeByIds(Arrays.asList(noteIds));

        return R.ok();
    }

    @RequestMapping("/getnotelist/{studentId}")
    public R getNoteList(@PathVariable("studentId")Integer studentId){
        List<NoteEntity> list = noteService.getNotesByStudentId(studentId);
        return R.ok().put("note",list);
    }

    @RequestMapping("/deletenote")
    public R deleteNote(@RequestBody NoteEntity noteEntity){
        noteService.deleteNote(noteEntity);
        return R.ok();
    }
}
